/**
 * 
 */
package daos;

import model.StudentClass;
import model.StudentProfile;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

public class StudentClassDAOImpl implements StudentClassDAO {
	private SessionFactory sessionFactory;
	
	
	@Transactional
	public void save(StudentClass studentClass) {
		Session session = this.sessionFactory.getCurrentSession();
		session.saveOrUpdate(studentClass);
	}

	@Transactional
	public StudentClass findStudentClassByID(int classID) {
		Session session = this.sessionFactory.getCurrentSession();
		return (StudentClass)session.get(StudentClass.class, classID);
	}
	
	@Transactional
	public List<StudentClass> findStudentClasses() {
		Session session = this.sessionFactory.getCurrentSession();
		Query query = session.createQuery("from StudentClass");
		return query.list();
	}

	@Transactional
	public void delete(StudentClass studentClass) {
		Session session = this.sessionFactory.getCurrentSession();
		session.delete(studentClass);
	}
	@Transactional
	public StudentClass getClassByName(String name) {
		Session session = this.sessionFactory.getCurrentSession();
		Query query = session.createQuery("from StudentClass where name=:name");
		query.setParameter("name", name);
		return (StudentClass)query.uniqueResult();
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
}